<div id="app">
    <admin-page-header>
        <bi-button icon="fa-plus" type="primary" @click="$go({action:'edit'})">添加分类</bi-button>
    </admin-page-header>

    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <bi-card title="分类列表">
                    <bi-table :data="list" :loading="loading" tree item-key="cate_id"  @dragsort="dragsort"  dragsort   min-height="300" :storagename="$user.getStorageName('shop-cate-list')" >
                        
                        <bi-table-column label="ID" name="cate_id" width="100"></bi-table-column>
                        <bi-table-column label="分类名称" name="title" tree-fold ></bi-table-column>
                        <bi-table-column label="操作" width="150" v-slot="{row}">
                            <bi-button type="primary" @click="$go({action:'edit',gets:{id:row.cate_id}})"  >编辑</bi-button>
                            <bi-button type="warning" @click="handleDel(row)" >删除</bi-button>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
        </div>
    </div>
</div>


<script>
    let app = admin.createApp({
        data(){
            return {
                list:[],
                loading:false
            }
        },
        methods:{
            getList(){
                this.loading = true;
                this.$ajax({
                    url:this.$url({action:'tree'}),
                    success:(res)=>{
                        this.loading = false;
                            this.list = res.tree;
                        }
                });
            },
            handleDel(item){
                this.$confirm({text:'确定删除？',type:'warning'},()=>{
                    this.$ajax({
                        url:this.$url({action:'del'}),
                        data:{
                            cate_id:item.cate_id
                        },
                        success:(res)=>{
                            this.getList();
                            this.$toast({text:'删除成功',type:'success'});
                        }
                    })
                })
            },
            dragsort(value){
                this.$loading();
                this.$ajax({
                    url:this.$url({action:'sort'}),
                    data:{
                        ids:value
                    },
                    success:(data)=>{
                        this.$loading(false)
                    }
                });
            }
        },
        mounted(){
            this.getList();
        }
    }).mount('#app');    
</script>